package cn.kgc.service.impl;

import cn.kgc.entity.PmsAttrAttrgroupRelation;
import cn.kgc.mapper.PmsAttrAttrgroupRelationMapper;
import cn.kgc.mapper.PmsAttrMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.mapper.PmsAttrGroupMapper;
import cn.kgc.entity.PmsAttrGroup;
import cn.kgc.service.PmsAttrGroupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 属性分组(PmsAttrGroup)表服务实现类
 *
 * @author makejava
 * @since 2022-11-29 15:03:29
 */
@Service("pmsAttrGroupService")
public class PmsAttrGroupServiceImpl extends ServiceImpl<PmsAttrGroupMapper, PmsAttrGroup> implements PmsAttrGroupService {

    @Resource
    private PmsAttrAttrgroupRelationMapper pmsAttrAttrgroupRelationMapper;
    @Resource
    private PmsAttrGroupMapper pmsAttrGroupMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    public boolean deleteAttrGroupAndRelation(Long attrGroupId) {
        pmsAttrGroupMapper.deleteById(attrGroupId);
        LambdaQueryWrapper<PmsAttrAttrgroupRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PmsAttrAttrgroupRelation::getAttrGroupId, attrGroupId);
        pmsAttrAttrgroupRelationMapper.delete(wrapper);
        return true;
    }
}
